// pages/activity/detail/index.js

const app = getApp();

var djs;

import {
  circleactivityDetail,
  circleactivityAdd,
  shareActive,
  activeLiveList,
  activeZongjie,
  circleactivityCancel,
  activeDelLive,
  activeLiveNew,
  signUser,
  ykActiveDetail,
  ykActiveLiveList,
  ykActiveLiveNew,
  ykSignUser
} from '../../../utils/http';
import WxParse from '../../../utils/wxParse/wxParse';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    v: app.globalData.v, //版本
    lang: app.vSwitch(), //版本
    theme: app.cSwitch(), //主题色
    patterns: app.globalData.patterns, //是否为游客模式
    isIphoneX: app.globalData.isIphoneX,

    // 分页
    page: 1,
    size: 10,
    pages: 0,
    current: 0,
    total: 0,
    noData: false,

    sharePath: '', //生成的分享图
    show: false,

    // popUpInfo: {
    //   img: '/pages/images/pop/1.png',
    //   tit: '欢迎使用' + app.config.wxApp.wxName + '平台',
    //   dec: '若想查看更多信息，请登录',
    //   url: '/pages/login/index',
    //   btnText: '点击登录'
    // },

    loginBox: false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    console.log(options)
    if (options.id) {
      this.setData({
        id: options.id
      })
    }
    if (options.shareUserid) {
      this.setData({
        shareUserid: options.shareUserid
      })
    }
    if (options.scene) {
      this.setData({
        id: options.scene
      })
    }

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    this.setData({
      dom: wx.createSelectorQuery().select('#hisLine').boundingClientRect()
    })
  },

  getData() {
    let t = this;
    return new Promise((resolve, reject) => {
      let func = app.globalData.patterns && !app.globalData.token ? ykActiveDetail : circleactivityDetail;
      func({
        id: t.data.id
      }).then(r => {
        if (r.code == 0) {
          r.data.details ? WxParse.wxParse('rule', 'html', r.data.details, t, 0) : '';
          r.data.signStartTime = r.data.signStartTime.substring(0, r.data.signStartTime.length - 3);
          r.data.signEndTime = r.data.signEndTime.substring(0, r.data.signEndTime.length - 3);
          r.data.activityStartTime = r.data.activityStartTime.substring(0, r.data.activityStartTime.length - 3);
          r.data.activityEndTime = r.data.activityEndTime.substring(0, r.data.activityEndTime.length - 3);
          t.setData({
            d: r.data
          })

          t.init();
          if (r.data.identity == 1 || r.data.identity == 2) {
            activeZongjie({
              aid: t.data.id
            }).then(r => {
              if (r.data) {
                if (r.data.dataList && r.data.dataList.length) {
                  let arr = [];
                  r.data.dataList.forEach(i => {
                    i.num ? arr.push(i) : '';
                  })
                  r.data.dataList = arr;
                }
                t.setData({
                  hb_d: r.data
                })
              }
              // t.drawPic();
            })
          }

          resolve();
        }
      })
    })

  },
  async init() {
    let t = this;
    t.setData({
      page: 1,
      pages: 0,
      current: 0,
      noData: false,
      list: [],
      signUser: []
    })
    t.getMore();
    t.mingdan();
  },
  mingdan() {
    let t = this;
    let func = app.globalData.patterns && !app.globalData.token ? ykSignUser : signUser;
    func({
      id: t.data.id,
      page: 1,
      pageSize: t.data.signUser && t.data.signUser.length ? 999 : 6
    }).then(r => {
      if (r.httpCode == 200 || r.code == 0) {
        let d = [];
        // if (!t.data.signUser || !t.data.signUser.length) {
        //   d = [];
        // } else {
        //   d = t.data.signUser;
        // }
        if (r.data.records.length) {
          r.data.records.forEach(i => {
            d.push(i)
          })
        }
        t.setData({
          signUser: d,
          ['d.signUpNum']: r.data.total
        })
      }
    })
  },
  getMore() {
    let t = this;
    clearInterval(djs);
    var promise = new Promise((resolve, reject) => {
      if (t.data.pages >= t.data.current) {
        // console.log(app.util.formatTime2());
        let func = app.globalData.patterns && !app.globalData.token ? ykActiveLiveList : activeLiveList;
        func({
          page: t.data.page,
          pageSize: t.data.size,
          activity: t.data.id,
          time: t.data.list && t.data.list.length ? t.data.list[t.data.list.length - 1].createTime : app.util.formatTime2()
        }).then(r => {
          if (r.httpCode == 200 || r.code == 0) {
            let d;
            let imgArr;
            if (t.data.page == 1) {
              d = [];
              imgArr = [];
            } else {
              d = t.data.list;
              imgArr = t.data.imgArr;
            }
            if (r.data.records.length) {
              r.data.records.forEach(i => {
                i.date = i.createTime.substr(0, 10);
                i.time = i.createTime.substr(11, 5);
                if (i.pic) {
                  imgArr.push(i.pic)
                }
                d.push(i)
              })
              if (r.data.records.length < r.data.size) {
                t.setData({
                  noData: true,
                })
              } else {
                t.setData({
                  noData: false,
                })
              }
            } else {
              t.setData({
                noData: true,
              })
            }
            t.setData({
              list: d,
              imgArr,
              page: ++t.data.page,
              pages: r.data.pages,
              current: r.data.current,
              total: r.data.total
            })
            if (t.data.d.activityRunStatus == 2) {
              djs = setInterval(() => {
                t.getNewLive();
              }, 10000)
            }

          }

          resolve();
        })
      } else {
        t.setData({
          noData: true
        })
        resolve();
      }
    });
    return promise;
  },

  getNewLive() {
    let t = this;
    return new Promise((resolve, reject) => {
      console.log('djs');
      let func = app.globalData.patterns && !app.globalData.token ? ykActiveLiveNew : activeLiveNew;
      func({
        activity: t.data.id,
        time: t.data.list && t.data.list.length ? t.data.list[0].createTime : app.util.formatTime2()
        // time: '2021-03-09 00:00:00'
      }).then(r => {
        if (r.code == 0 && r.data && r.data.length) {
          let list = t.data.list && t.data.list.length ? t.data.list : [];
          let imgArr = t.data.imgArr && t.data.imgArr.length ? t.data.imgArr : [];
          r.data.forEach(i => {
            i.date = i.createTime.substr(0, 10);
            i.time = i.createTime.substr(11, 5);
            if (i.pic) {
              imgArr.push(i.pic)
            }
            list.unshift(i);
          })
          t.setData({
            list,
            imgArr
          })

        }
      })
    })
  },

  // 图文直播图片预览
  imgPreview(e) {
    wx.previewImage({
      current: e.mark.img, // 当前显示图片的http链接
      urls: this.data.imgArr // 需要预览的图片http链接列表
    })
  },

  // onPageScroll: function (e) {
  //   console.log(e); //{scrollTop:99}
  //   this.data.dom.exec(function (res) {
  //     console.log(res);
  //   })
  //   wx.getSystemInfo({
  //     success: function (res, rect) {
  //       console.log(res);
  //     }
  //   })
  // },

  comeHere(e) {
    app.location(e.mark)
  },

  baoming() {
    let t = this;
    if (t.data.patterns) {
      if (!app.globalData.token) {
        t.setData({
          loginBox: true
        })
        return false;
      }
    }
    app.message().then(r => {
      if (!t.data.patterns) {
        t.baomingSubmit();
      } else {
        wx.navigateTo({
          url: '/pages/mine/info/index?type=youke',
        })
      }
    })

  },

  baomingSubmit() {
    let t = this;
    wx.showModal({
      title: '提示',
      content: '确定要报名活动吗？',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
          let _data = {
            activityId: t.data.id
          }
          if (t.data.patterns) {
            let info = wx.getStorageSync('userInfo');
            _data.name = info.name;
            _data.phone = info.phone;
          }
          circleactivityAdd(_data).then(r => {
            if (r.code == 0) {
              wx.showToast({
                title: '报名成功',
                mask: true
              })
              setTimeout(() => {
                t.getData();
              }, 1500)
              // t.setData({
              //   ['d.isSignMySelf']: 2
              // })
            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })

  },

  // 取消报名
  qxBaoming() {
    let t = this;
    app.message().then(r => {
      wx.showModal({
        title: '提示',
        content: '若确认取消后不可再报名此活动，确定要取消报名活动吗？',
        success(res) {
          if (res.confirm) {
            console.log('用户点击确定')
            circleactivityCancel({
              activityId: t.data.id
            }).then(r => {
              if (r.code == 0) {
                wx.showToast({
                  title: '取消报名成功',
                  mask: true
                })
                setTimeout(() => {
                  t.getData();
                }, 1500)
                // t.setData({
                //   ['d.isSignMySelf']: 2
                // })
              }
            })
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      theme: app.cSwitch(), //主题色
      patterns: app.globalData.patterns, //是否为游客模式
    })
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: this.data.theme.tabbarColor,
    })
    let t = this;
    // if (app.globalData.token) {
    //   t.setData({
    //     popUpshow: false
    //   })
    if (!this.data.d) {
      if (t.data.patterns) {
        this.getData().then(() => {
          if (t.data.shareUserid) {
            shareActive({
              aid: t.data.id,
              shareUserid: t.data.shareUserid
            })
          }
        });
      } else {
        app.userInfo().then(r => {
          this.setData({
            info: r
          })
          if (r.headPic && r.organizationalId) {
            this.getData().then(() => {
              if (t.data.shareUserid) {
                shareActive({
                  aid: t.data.id,
                  shareUserid: t.data.shareUserid
                })
              }
            });
          } else {
            wx.navigateTo({
              url: '/pages/mine/info/index',
            })
          }

        })

      }
    }
    // } else {
    //   t.setData({
    //     popUpshow: true
    //   })
    // }
  },

  loginAfter() {
    this.setData({
      d: null
    })
    this.onShow();
  },

  goPage(e) {
    app.goPage(e.mark)
  },



  handlePhotoSaved() {
    this.savePhoto(this.data.sharePath)
  },
  close() {
    let t = this;
    t.setData({
      show: false
    })
  },
  drawPic() {
    let t = this;
    t.setData({
      show: true
    })
    if (this.data.sharePath) { //如果已经绘制过了本地保存有图片不需要重新绘制
      this.setData({
        visible: true
      })
      return
    }
    let style = [{
      type: 'image',
      url: '/pages/images/hb1.png',
      css: {
        top: '-175rpx',
        left: '0',
        right: '0',
        width: '750rpx',
        height: '730rpx'
      }
    }, {
      type: 'image',
      url: '/pages/images/hb2.png',
      css: {
        top: '28rpx',
        left: '28rpx',
        width: '157rpx',
        height: '54rpx'
      }
    }, {
      type: 'text',
      text: '参加' + t.data.hb_d.circleActivity.totle + '活动总结报告',
      css: {
        top: '135rpx',
        left: '187rpx',
        right: '187rpx',
        fontSize: '42rpx',
        color: '#2DFCFF',
        fontWeight: '800',
        textAlign: 'center',
        width: '376rpx',
        height: '54rpx',
        lineHeight: '60rpx'
      }
    }, {
      type: 'text',
      text: '地点:' + t.data.hb_d.circleActivity.address,
      css: {
        top: '292rpx',
        left: '0rpx',
        right: '0rpx',
        fontSize: '26rpx',
        color: '#FF7D76',
        fontWeight: '500',
        textAlign: 'center',
        width: '750rpx'
      }
    }, {
      type: 'text',
      text: t.data.hb_d.circleActivity.activityStartTime.substring(0, t.data.hb_d.circleActivity.activityStartTime.length - 3) + ' ~ ' + t.data.hb_d.circleActivity.activityEndTime.substring(0, t.data.hb_d.circleActivity.activityEndTime.length - 3),
      css: {
        top: '342rpx',
        left: '0rpx',
        right: '0rpx',
        fontSize: '24rpx',
        color: '#24EBFF',
        fontWeight: '500',
        textAlign: 'center',
        width: '750rpx'
      }
    }, {
      type: 'image',
      url: t.data.hb_d.userVo.headPic,
      css: {
        top: '400rpx',
        left: '312rpx',
        width: '120rpx',
        height: '120rpx',
        borderColor: '#ffffff',
        borderRadius: '50%',
        borderWidth: '3rpx'
      }
    }, {
      type: 'rect',
      css: {
        top: '500rpx',
        left: '334rpx',
        width: '82rpx',
        height: '30rpx',
        borderColor: '#ffffff',
        borderRadius: '15rpx',
        borderWidth: '2rpx',
        color: 'linear-gradient(0deg, #FFB587 0%, #FF4363 100%)'
      }
    }, {
      type: 'text',
      text: '发起人',
      css: {
        top: '500rpx',
        left: '0rpx',
        right: '0rpx',
        fontSize: '20rpx',
        color: '#ffffff',
        fontWeight: '500',
        fontHeight: '30rpx',
        textAlign: 'center',
        width: '750rpx'
      }
    }, {
      type: 'text',
      text: t.data.hb_d.userVo.name,
      css: {
        top: '545rpx',
        left: '0rpx',
        right: '0rpx',
        fontSize: '32rpx',
        color: '#ffffff',
        fontWeight: '500',
        textAlign: 'center',
        width: '750rpx'
      }
    }, {
      type: 'text',
      text: t.data.hb_d.userVo.position ? (t.data.lang.a1 + '：' + t.data.hb_d.userVo.position) : '',
      css: {
        top: '591rpx',
        left: '0rpx',
        right: '0rpx',
        fontSize: '24rpx',
        color: '#ffffff',
        fontWeight: '400',
        textAlign: 'center',
        width: '750rpx'
      }
    }, {
      type: 'text',
      text: t.data.hb_d.activityPeopleNum + '人',
      css: {
        top: '693rpx',
        left: '61rpx',
        fontSize: '36rpx',
        color: '#2DFCFF',
        fontWeight: '800',
        textAlign: 'center',
        width: '150rpx'
      }
    }, {
      type: 'text',
      text: '参与活动人数',
      css: {
        top: '746rpx',
        left: '61rpx',
        fontSize: '24rpx',
        color: '#2DFCFF',
        fontWeight: '500',
        textAlign: 'center',
        width: '150rpx'
      }
    }, {
      type: 'text',
      text: t.data.hb_d.livePeopleNum + '人',
      css: {
        top: '693rpx',
        left: '304rpx',
        fontSize: '36rpx',
        color: '#FF4548',
        fontWeight: '800',
        textAlign: 'center',
        width: '150rpx'
      }
    }, {
      type: 'text',
      text: '互动直播人数',
      css: {
        top: '746rpx',
        left: '304rpx',
        fontSize: '24rpx',
        color: '#FF4548',
        fontWeight: '500',
        textAlign: 'center',
        width: '150rpx'
      }
    }, {
      type: 'text',
      text: t.data.hb_d.views + '次',
      css: {
        top: '693rpx',
        left: '547rpx',
        fontSize: '36rpx',
        color: '#FFD83D',
        fontWeight: '800',
        textAlign: 'center',
        width: '150rpx'
      }
    }, {
      type: 'text',
      text: '活动浏览量',
      css: {
        top: '746rpx',
        left: '547rpx',
        fontSize: '24rpx',
        color: '#FFD83D',
        fontWeight: '500',
        textAlign: 'center',
        width: '150rpx'
      }
    }, {
      type: 'text',
      text: '数据展示',
      css: {
        top: '868rpx',
        left: '0rpx',
        fontSize: '40rpx',
        color: '#2DFCFF',
        fontWeight: '800',
        textAlign: 'center',
        width: '750rpx',
      }
    }, {
      type: 'image',
      url: '/pages/images/hb3.png',
      css: {
        top: '885rpx',
        left: '110rpx',
        width: '164rpx',
        height: '18rpx',
      }
    }, {
      type: 'image',
      url: '/pages/images/hb3.png',
      css: {
        top: '885rpx',
        right: '110rpx',
        width: '164rpx',
        height: '18rpx',
        rotate: '180'
      }
    }, {
      type: 'image',
      url: '/pages/images/hb5.png',
      css: {
        top: '990rpx',
        left: '100rpx',
        width: '44rpx',
        height: '63rpx',
      }
    }, {
      type: 'rect',
      css: {
        top: '992rpx',
        left: '174rpx',
        width: '4rpx',
        height: '61rpx',
        borderRadius: '2rpx',
        color: 'linear-gradient(0deg, #FF4C51 0%, #FB4E8A 100%)'
      }
    }, {
      type: 'text',
      text: t.data.hb_d.girlNum + '人',
      css: {
        top: '985rpx',
        left: '197rpx',
        fontSize: '36rpx',
        color: '#ffffff',
        fontWeight: '700',
      }
    }, {
      type: 'text',
      text: '女性用户',
      css: {
        top: '1025rpx',
        left: '197rpx',
        fontSize: '24rpx',
        color: '#ffffff',
        fontWeight: '400',
      }
    }, {
      type: 'image',
      url: '/pages/images/hb4.png',
      css: {
        top: '990rpx',
        left: '457rpx',
        width: '44rpx',
        height: '63rpx',
      }
    }, {
      type: 'rect',
      css: {
        top: '992rpx',
        left: '535rpx',
        width: '4rpx',
        height: '61rpx',
        borderRadius: '2rpx',
        color: 'linear-gradient(0deg,  #3782FF 0%, #1E98FA 100%)'
      }
    }, {
      type: 'text',
      text: t.data.hb_d.manNum + '人',
      css: {
        top: '985rpx',
        left: '558rpx',
        fontSize: '36rpx',
        color: '#ffffff',
        fontWeight: '700',
      }
    }, {
      type: 'text',
      text: '男性用户',
      css: {
        top: '1025rpx',
        left: '558rpx',
        fontSize: '24rpx',
        color: '#ffffff',
        fontWeight: '400',
      }
    }];

    // 兴趣分析
    style.push({
      type: 'text',
      text: '兴趣分析',
      css: {
        top: '1150rpx',
        left: '0rpx',
        fontSize: '40rpx',
        color: '#2DFCFF',
        fontWeight: '800',
        textAlign: 'center',
        width: '750rpx',
      }
    }, {
      type: 'image',
      url: '/pages/images/hb3.png',
      css: {
        top: '1167rpx',
        left: '110rpx',
        width: '164rpx',
        height: '18rpx',
      }
    }, {
      type: 'image',
      url: '/pages/images/hb3.png',
      css: {
        top: '1167rpx',
        right: '110rpx',
        width: '164rpx',
        height: '18rpx',
        rotate: '180'
      }
    }, {
      type: 'text',
      text: '参与该活动用户的共同兴趣标签',
      css: {
        top: '1238rpx',
        left: '0rpx',
        fontSize: '28rpx',
        color: '#ffffff',
        fontWeight: '500',
        textAlign: 'center',
        width: '750rpx',
      }
    }, {
      type: 'rect',
      css: {
        top: '1389rpx',
        left: '209rpx',
        width: '324rpx',
        height: '324rpx',
        borderRadius: '50%',
        borderColor: 'rgba(28, 44, 135, 1)',
        color: 'rgba(8, 16, 60, 0)',
        borderWidth: '1rpx'
      }
    }, {
      type: 'rect',
      css: {
        top: '1409rpx',
        left: '229rpx',
        width: '282rpx',
        height: '282rpx',
        borderRadius: '50%',
        borderColor: 'rgba(28, 44, 135, 1)',
        color: 'rgba(8, 16, 60, 0)',
        borderWidth: '1rpx'
      }
    })
    if (t.data.hb_d.dataList) {
      if (t.data.hb_d.dataList[0]) {
        style.push({
          type: 'rect',
          css: {
            top: '1376rpx',
            left: '172rpx',
            width: '118rpx',
            height: '118rpx',
            borderRadius: '50%',
            borderColor: 'rgba(244, 117, 83, .3)',
            color: 'rgba(8, 16, 60, 0)',
            borderWidth: '1rpx'
          }
        }, {
          type: 'rect',
          css: {
            top: '1380rpx',
            left: '176rpx',
            width: '110rpx',
            height: '110rpx',
            borderRadius: '50%',
            color: '#DEB62E'
          }
        }, {
          type: 'text',
          text: t.data.hb_d.dataList[0].name,
          css: {
            top: '1410rpx',
            left: '176rpx',
            width: '110rpx',
            height: '110rpx',
            color: '#ffffff',
            textAlign: 'center',
            fontSize: '20rpx',
            fontWeight: '500'
          }
        }, {
          type: 'text',
          text: t.data.hb_d.dataList[0].num + '人',
          css: {
            top: '1437rpx',
            left: '176rpx',
            width: '110rpx',
            height: '110rpx',
            color: '#ffffff',
            textAlign: 'center',
            fontSize: '28rpx',
            fontWeight: '800'
          }
        })
      }
      if (t.data.hb_d.dataList[1]) {
        style.push({
          type: 'rect',
          css: {
            top: '1347rpx',
            left: '335rpx',
            width: '82rpx',
            height: '82rpx',
            borderRadius: '50%',
            borderColor: 'rgba(244, 85, 119, .3)',
            color: 'rgba(8, 16, 60, 0)',
            borderWidth: '1rpx'
          }
        }, {
          type: 'rect',
          css: {
            top: '1351rpx',
            left: '339rpx',
            width: '74rpx',
            height: '74rpx',
            borderRadius: '50%',
            color: '#F45577'
          }
        }, {
          type: 'text',
          text: t.data.hb_d.dataList[1].name,
          css: {
            top: '1365rpx',
            left: '339rpx',
            width: '74rpx',
            height: '74rpx',
            color: '#ffffff',
            textAlign: 'center',
            fontSize: '20rpx',
            fontWeight: '500'
          }
        }, {
          type: 'text',
          text: t.data.hb_d.dataList[1].num + '人',
          css: {
            top: '1394rpx',
            left: '339rpx',
            width: '74rpx',
            height: '74rpx',
            color: '#ffffff',
            textAlign: 'center',
            fontSize: '20rpx',
            fontWeight: '800'
          }
        })

      }
      if (t.data.hb_d.dataList[2]) {
        style.push({
          type: 'rect',
          css: {
            top: '1406rpx',
            left: '457rpx',
            width: '112rpx',
            height: '112rpx',
            borderRadius: '50%',
            borderColor: 'rgba(72, 189, 110, .3)',
            color: 'rgba(8, 16, 60, 0)',
            borderWidth: '1rpx'
          }
        }, {
          type: 'rect',
          css: {
            top: '1410rpx',
            left: '461rpx',
            width: '104rpx',
            height: '104rpx',
            borderRadius: '50%',
            color: '#48BD6E'
          }
        }, {
          type: 'text',
          text: t.data.hb_d.dataList[2].name,
          css: {
            top: '1440rpx',
            left: '461rpx',
            width: '104rpx',
            height: '104rpx',
            color: '#ffffff',
            textAlign: 'center',
            fontSize: '20rpx',
            fontWeight: '500'
          }
        }, {
          type: 'text',
          text: t.data.hb_d.dataList[2].num + '人',
          css: {
            top: '1464rpx',
            left: '461rpx',
            width: '104rpx',
            height: '104rpx',
            color: '#ffffff',
            textAlign: 'center',
            fontSize: '28rpx',
            fontWeight: '800'
          }
        })
      }
      if (t.data.hb_d.dataList[3]) {
        style.push({
          type: 'rect',
          css: {
            top: '1590rpx',
            left: '196rpx',
            width: '98rpx',
            height: '98rpx',
            borderRadius: '50%',
            borderColor: 'rgba(166, 105, 225, .3)',
            color: 'rgba(8, 16, 60, 0)',
            borderWidth: '1rpx'
          }
        }, {
          type: 'rect',
          css: {
            top: '1594rpx',
            left: '200rpx',
            width: '90rpx',
            height: '90rpx',
            borderRadius: '50%',
            color: '#A669E1'
          }
        }, {
          type: 'text',
          text: t.data.hb_d.dataList[3].name,
          css: {
            top: '1617rpx',
            left: '200rpx',
            width: '90rpx',
            height: '90rpx',
            color: '#ffffff',
            textAlign: 'center',
            fontSize: '20rpx',
            fontWeight: '500'
          }
        }, {
          type: 'text',
          text: t.data.hb_d.dataList[3].num + '人',
          css: {
            top: '1641rpx',
            left: '200rpx',
            width: '90rpx',
            height: '90rpx',
            color: '#ffffff',
            textAlign: 'center',
            fontSize: '20rpx',
            fontWeight: '800'
          }
        })
      }
      if (t.data.hb_d.dataList[4]) {
        style.push({
          type: 'rect',
          css: {
            top: '1471rpx',
            left: '289rpx',
            width: '160rpx',
            height: '160rpx',
            borderRadius: '50%',
            borderColor: 'rgba(166, 105, 225, .3)',
            color: 'rgba(8, 16, 60, 0)',
            borderWidth: '1rpx'
          }
        }, {
          type: 'rect',
          css: {
            top: '1475rpx',
            left: '293rpx',
            width: '152rpx',
            height: '152rpx',
            borderRadius: '50%',
            color: 'linear-gradient(180deg, #EB5755 0%, #F98751 100%)'
          }
        }, {
          type: 'text',
          text: t.data.hb_d.dataList[4].name,
          css: {
            top: '1517rpx',
            left: '293rpx',
            width: '152rpx',
            height: '152rpx',
            color: '#ffffff',
            textAlign: 'center',
            fontSize: '24rpx',
            fontWeight: '500'
          }
        }, {
          type: 'text',
          text: t.data.hb_d.dataList[4].num + '人',
          css: {
            top: '1554rpx',
            left: '293rpx',
            width: '152rpx',
            height: '152rpx',
            color: '#ffffff',
            textAlign: 'center',
            fontSize: '34rpx',
            fontWeight: '800'
          }
        })
      }
      if (t.data.hb_d.dataList[5]) {
        style.push({
          type: 'rect',
          css: {
            top: '1606rpx',
            left: '430rpx',
            width: '82rpx',
            height: '82rpx',
            borderRadius: '50%',
            borderColor: 'rgba(67, 224, 226, .3)',
            color: 'rgba(8, 16, 60, 0)',
            borderWidth: '1rpx'
          }
        }, {
          type: 'rect',
          css: {
            top: '1610rpx',
            left: '434rpx',
            width: '74rpx',
            height: '74rpx',
            borderRadius: '50%',
            color: '#43E0E2'
          }
        }, {
          type: 'text',
          text: t.data.hb_d.dataList[5].name,
          css: {
            top: '1626rpx',
            left: '434rpx',
            width: '74rpx',
            height: '74rpx',
            color: '#ffffff',
            textAlign: 'center',
            fontSize: '20rpx',
            fontWeight: '500'
          }
        }, {
          type: 'text',
          text: t.data.hb_d.dataList[5].num + '人',
          css: {
            top: '1650rpx',
            left: '434rpx',
            width: '74rpx',
            height: '74rpx',
            color: '#ffffff',
            textAlign: 'center',
            fontSize: '20rpx',
            fontWeight: '800'
          }
        })
      }
    }
    let drawheight = 1750;
    // 图文直播互动
    if (t.data.hb_d.circleActivityProgressList && t.data.hb_d.circleActivityProgressList.length) {
      drawheight = drawheight + 200;
      let h = 360;
      let length = t.data.hb_d.circleActivityProgressList.length > 4 ? 4 : t.data.hb_d.circleActivityProgressList.length;
      style.push({
        type: 'text',
        text: '图文直播互动',
        css: {
          top: '1800rpx',
          left: '0rpx',
          fontSize: '40rpx',
          color: '#2DFCFF',
          fontWeight: '800',
          textAlign: 'center',
          width: '750rpx',
        }
      }, {
        type: 'image',
        url: '/pages/images/hb3.png',
        css: {
          top: '1820rpx',
          left: '91rpx',
          width: '164rpx',
          height: '18rpx',
        }
      }, {
        type: 'image',
        url: '/pages/images/hb3.png',
        css: {
          top: '1820rpx',
          right: '91rpx',
          width: '164rpx',
          height: '18rpx',
          rotate: '180'
        }
      }, {
        type: 'rect',
        css: {
          top: (drawheight + 20) + 'rpx',
          left: '371rpx',
          width: '8rpx',
          height: (h * length) + 'rpx',
          color: 'linear-gradient(180deg, #04B6BB 0%, #2DC6FF 100%)',
          borderRadius: '4rpx'
        }
      })
      let padding = 40;
      t.data.hb_d.circleActivityProgressList.forEach((i, index) => {
        if (index < 4) {
          i.date = i.createTime.substr(0, 10);
          i.time = i.createTime.substr(11, 5);
          style.push({
            type: 'rect',
            css: {
              top: drawheight + 'rpx',
              left: '350rpx',
              width: '54rpx',
              height: '54rpx',
              borderRadius: '50%',
              color: 'radial-gradient(rgba(35, 203, 205, 0.2) 0%, rgba(35, 203, 205, 0) 100%)',
            }
          }, {
            type: 'rect',
            css: {
              top: (drawheight + 16) + 'rpx',
              left: '366rpx',
              width: '18rpx',
              height: '18rpx',
              borderRadius: '50%',
              color: '#2DFCFF',
            }
          }, {
            type: 'rect',
            css: {
              top: (drawheight + 16) + 'rpx',
              left: '40rpx',
              width: '280rpx',
              height: '336rpx',
              color: 'rgba(8, 16, 60, 0)',
            }
          })
          style.push({
            type: 'rect',
            css: {
              left: index % 2 ? '424rpx' : padding + 'rpx',
              top: drawheight + 'rpx',
              width: '280rpx',
              height: '48rpx',
              color: 'linear-gradient(-90deg, #0A3D5D 0%, #08103C 100%)',
              borderRadius: '10rpx 0px 0px 10rpx'
            }
          }, {
            type: 'text',
            text: i.date,
            css: {
              top: (drawheight + 12) + 'rpx',
              left: index % 2 ? '445rpx' : '60rpx',
              fontSize: '24rpx',
              fontHeight: '24rpx',
              color: '#43E0E2',
              fontWeight: '500',
              fontStyle: 'italic'
            }
          }, {
            type: 'text',
            text: i.time,
            css: {
              top: (drawheight + 14) + 'rpx',
              left: index % 2 ? '610rpx' : '225rpx',
              fontSize: '20rpx',
              fontHeight: '20rpx',
              color: '#43E0E2',
              fontWeight: '500',
              fontStyle: 'italic'
            }
          })

          i.title ? style.push({
            type: 'text',
            text: i.title,
            css: {
              top: (drawheight + 78) + 'rpx',
              left: index % 2 ? '424rpx' : padding + 'rpx',
              width: '280rpx',
              fontSize: '20rpx',
              fontHeight: '48rpx',
              color: '#43E0E2',
              fontWeight: '500',
              fontStyle: 'italic'
            }
          }) : ''

          i.pic ? style.push({
            type: 'image',
            url: i.pic,
            css: {
              top: i.title ? (drawheight + 150) + 'rpx' : (drawheight + 78) + 'rpx',
              left: index % 2 ? '424rpx' : padding + 'rpx',
              width: '280rpx',
              height: '158rpx',
              borderRadius: '8rpx'
            }
          }) : '';


          drawheight = drawheight + h;
        }
      })



    }

    style.push({
      type: 'image',
      url: t.data.hb_d.qrcode,
      css: {
        top: drawheight + 290 + 'rpx',
        left: '290rpx',
        width: '170rpx',
        height: '170rpx'
      }
    }, {
      type: 'image',
      url: '/pages/images/hb6.png',
      css: {
        top: drawheight + 80 + 'rpx',
        left: '284rpx',
        width: '166rpx',
        height: '173rpx'
      }
    }, {
      type: 'image',
      url: '/pages/images/hb7.png',
      css: {
        bottom: '0rpx',
        left: '0rpx',
        width: '750rpx',
        height: '489rpx'
      }
    })
    drawheight = drawheight + 530;

    wx.showLoading({
      title: '生成中',
      mask: true
    })
    this.setData({
      imgDraw: {
        width: '750rpx',
        height: drawheight + 'rpx',
        background: '#08103C',
        views: style
      }
    })
  },
  onImgErr(e) {
    wx.hideLoading()
    wx.showToast({
      title: '生成分享图失败，请刷新页面重试'
    })
  },
  onImgOK(e) {
    wx.hideLoading()
    this.setData({
      sharePath: e.detail.path,
      visible: true,
    })
    //通知外部绘制完成，重置isCanDraw为false
    this.triggerEvent('initData')
  },
  preventDefault() {},
  // 保存图片
  savePhoto(path) {
    wx.showLoading({
      title: '正在保存...',
      mask: true
    })
    this.setData({
      isDrawImage: false
    })
    wx.saveImageToPhotosAlbum({
      filePath: path,
      success: (res) => {
        wx.showToast({
          title: '保存成功',
          icon: 'none',
          mask: true
        })
        setTimeout(() => {
          this.setData({
            visible: false
          })
        }, 300)
      },
      fail: (res) => {
        wx.getSetting({
          success: res => {
            let authSetting = res.authSetting
            if (!authSetting['scope.writePhotosAlbum']) {
              this.setData({
                isModal: true
              })
            }
          }
        })
        setTimeout(() => {
          wx.hideLoading()
          this.setData({
            visible: false
          })
        }, 300)
      }
    })
  },

  // 删除我发布的图文直播
  delLive(e) {
    let t = this;
    wx.showModal({
      title: '提示',
      content: '确定要删除您发布的此条图文直播吗？',
      success(res) {
        if (res.confirm) {
          console.log('用户点击确定')
          activeDelLive({
            id: e.mark.id
          }).then(r => {
            if (r.code == 0) {
              wx.showToast({
                title: '删除成功',
                mask: true
              })
              setTimeout(() => {
                t.init();
              }, 1500)

            }
          })
        } else if (res.cancel) {
          console.log('用户点击取消')
        }
      }
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    clearInterval(djs);
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    clearInterval(djs);
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.getData();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (!this.data.noData) {
      this.getMore();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let name;
    let wxApp = app.config.wxApp;
    let info = wx.getStorageSync('userInfo');
    if (info) {
      name = info.name + '为您分享活动“' + this.data.d.totle + '”';
      if (this.data.d.activityType == 3) {
        name = info.name + '邀请您参与私密活动';
      }
    } else {
      name = '“' + this.data.d.totle + '”';
    }
    return app.share({
      name,
      url: '/pages/activity/detail/index?id=' + this.data.id + '&shareUserid=' + info.id,
      // img: this.data.d.activityType == 3 ? wxApp.smShare : (this.data.d.pic ? this.data.d.pic : wxApp.hdShare)
      img: this.data.d.pic ? this.data.d.pic : (this.data.d.activityType == 3 ? wxApp.smShare : wxApp.hdShare)
    });
  }
})